package com.xuecheng.manage_cms.controller;

import com.xuecheng.api.cms.CmsPagePreviewControllerApi;
import com.xuecheng.framework.web.BaseController;
import com.xuecheng.manage_cms.service.CmsPageService;
import com.xuecheng.manage_cms.service.impl.CmsPageServiceImpl;
import freemarker.template.TemplateException;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.io.IOException;
@Api("静态页面预览")
@Controller
public class CmsPagePreviewController extends BaseController implements CmsPagePreviewControllerApi {

    @Autowired
    CmsPageServiceImpl cmsPageService;


    @GetMapping("/cms/preview/{pageId}")
    @Override
    public void preview(@PathVariable("pageId") String pageId) throws IOException, TemplateException {
        String staticPageHtml = cmsPageService.getStaticPageHtml(pageId);
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(staticPageHtml);
    }
}
